package com.mydomain.data;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;
import com.mydomain.domain.Account;

import java.io.Reader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.sql.SQLException;

public class SimpleExample {

	private static SqlMapClient sqlMapper;

	static {
		try {
			Reader reader = Resources.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			// Fail fast.
			throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
		}
	}

	public static Map selectAccountMap() throws SQLException {
		return sqlMapper.queryForMap("selectAllAccounts", null, "id");
	}

	public static Map selectAccountMapValue() throws SQLException {
		return sqlMapper.queryForMap("selectAllAccounts", null, "id", "emailAddress");
	}
}